package ${controllerPackage};

import ${entityPackage}.${entity};
import ${servicePackage}.${entity}Service;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.data.domain.*;
import org.springframework.web.bind.annotation.*;

import java.util.HashMap;
import java.util.List;
import java.util.Map;

/**
 * @Description: ${table.comment}控制台
 * @Author: ${author}
 * @Date: ${date}
 **/
@RestController
@RequestMapping(value="/${entity?uncap_first}")
public class ${entity}Controller {
    private static final Logger logger = LoggerFactory.getLogger(${entity}Controller.class);
    @Autowired
    private ${entity}Service ${entity?uncap_first}Service;

    //查询
    @RequestMapping(value = "/query")
    public Map query(){
        Map map_res = new HashMap();
        ${entity} search = new ${entity}();
        Example<${entity}> example =Example.of(search);
        Sort sort = Sort.by(Sort.Direction.DESC, "id");
        Pageable page = PageRequest.of(0,5,sort);
        Page pages = ${entity?uncap_first}Service.findAll(example,page);
        List<${entity}> content = pages.getContent();
        map_res.put("total",pages.getTotalElements());
        map_res.put("list",content);
        return map_res;
    }

    @RequestMapping(value = "/add")
    public Map add_one_boy(){
        Map map_res = new HashMap();
        try{
            ${entity} entity = new ${entity}();
            entity.setUsername("Username");
            entity.setPassword("Password");
            entity = ${entity?uncap_first}Service.save(entity);
            map_res.put("res",entity);
        }catch(Exception e){
            System.out.println("添加user异常："+e.getMessage());
        }
        return map_res;
    }

}
